package controllers

import (
	"autoPage/models"

	"github.com/pquerna/ffjson/ffjson"
	"strconv"
)

type AlgoInfoConfigController struct {
	BaseController
}

func (dc *AlgoInfoConfigController) URLMapping() {
	dc.Mapping("Add", dc.Add)
	dc.Mapping("ToDev", dc.ToDev)
}
func (dc *AlgoInfoConfigController) ToDev() {
	dc.ShowMsg("模块暂未开放！", "/pageconfig/list", 2)
}

//新增算法
func (dc *AlgoInfoConfigController) Add() {
	urlparams := dc.GetUrlQuery()
	id := urlparams.Get("id")

	if dc.IsSubmit() {
		dc.ShowMsg("暂未开通保存算法权限", "/algoinfoconfig/add?id=1", 1)
		return

	} else {
		m := make(map[string]interface{})
		if id != "" {
			idInt, _ := strconv.ParseInt(id, 10, 64)
			algoConfig, err := models.GetAlgoInfoConfigById(idInt)
			if err == nil {
				alb, _ := ffjson.Marshal(algoConfig)
				ffjson.Unmarshal(alb, &m)
			}
		}
		dc.Data["alaction"] = "add"
		dc.Data["ActiveTab"] = "algoinfoconfig"
		dc.Data["ActiveMenu"] = "algoinfoconfig"

		dc.Data["t"] = "algo"
		dc.Data["configItems"], _ = GetConfigItems("AlgoInfo", m)
		dc.TplName = "algo_config/info.html"
	}

}
